//package com.u2b.db.utils;
//import java.util.Hashtable;
//import java.util.Properties;
//
//import javax.naming.Context;
//import javax.naming.Name;
//import javax.naming.spi.ObjectFactory;
//import javax.sql.DataSource;
//
//import org.apache.commons.dbcp.BasicDataSource;
//
//import com.sina.sae.util.SaeUserInfo;
//public class BasicDataSourceFactory implements ObjectFactory {
//    private final static String PROP_DRIVERCLASSNAME = "driverClassName";
//    private final static String PROP_MAXACTIVE = "maxActive";
//    private final static String PROP_MAXIDLE = "maxIdle";
//    private final static String PROP_MINIDLE = "minIdle";
//    private final static String PROP_INITIALSIZE = "initialSize";
//    private final static String PROP_MAXWAIT = "maxWait";
//    private final static String PROP_PASSWORD = "password";
//    private final static String PROP_URL = "url";
//    private final static String PROP_USERNAME = "username";
//    private final static String PROP_SAE_USED="isSaeUse";
//    private final static String PROP_SAE_READ_URL="saeReadDB";
//    private final static String PROP_SAE_WRITE_URL="saeWriteDB";
//
//    private final static String[] ALL_PROPERTIES = {
//        
//        PROP_DRIVERCLASSNAME,
//        PROP_MAXACTIVE,
//        PROP_MAXIDLE,
//        PROP_MINIDLE,
//        PROP_INITIALSIZE,
//        PROP_MAXWAIT,
//        PROP_SAE_USED,
//        PROP_SAE_READ_URL,
//        PROP_SAE_WRITE_URL,
//        PROP_PASSWORD,
//        PROP_URL,
//        PROP_USERNAME,
//
//    };
//    public static DataSource createDataSource(Properties properties,boolean isReadDB) throws Exception {
//        BasicDataSource dataSource = new BasicDataSource();
//        String value = null;
//
//        value = properties.getProperty(PROP_DRIVERCLASSNAME);
//        if (value != null) {
//            dataSource.setDriverClassName(value);
//        }
//
//        value = properties.getProperty(PROP_MAXACTIVE);
//        if (value != null) {
//            dataSource.setMaxActive(Integer.parseInt(value));
//        }
//
//        value = properties.getProperty(PROP_MAXIDLE);
//        if (value != null) {
//            dataSource.setMaxIdle(Integer.parseInt(value));
//        }
//
//        value = properties.getProperty(PROP_MINIDLE);
//        if (value != null) {
//            dataSource.setMinIdle(Integer.parseInt(value));
//        }
//
//        value = properties.getProperty(PROP_INITIALSIZE);
//        if (value != null) {
//            dataSource.setInitialSize(Integer.parseInt(value));
//        }
//
//        value = properties.getProperty(PROP_MAXWAIT);
//        if (value != null) {
//            dataSource.setMaxWait(Long.parseLong(value));
//        }
//       isUseSae(properties, dataSource,isReadDB);
//        if (dataSource.getInitialSize() > 0) {
//            dataSource.getLogWriter();
//        }
//
//      
//        return dataSource;
//    }
//
//	private static void isUseSae(Properties properties,BasicDataSource dataSource,boolean isReadDB) {
//		String value;
//		value=properties.getProperty(PROP_SAE_USED);
//		   if(!(Boolean.valueOf(value).booleanValue())){
//		    value = properties.getProperty(PROP_PASSWORD);
//		    if (value != null) {
//		        dataSource.setPassword(value);
//		    }		     
//		    value = properties.getProperty(PROP_URL);
//		    if (value != null) {
//		        dataSource.setUrl(value);
//		    }
//
//		    value = properties.getProperty(PROP_USERNAME);
//		    if (value != null) {
//		        dataSource.setUsername(value);
//		    }
//		   }
//		   else{
//			   if(isReadDB)
//			    value = properties.getProperty(PROP_SAE_READ_URL);
//			   else
//				   value = properties.getProperty(PROP_SAE_WRITE_URL); 
//			    String user = SaeUserInfo.getAccessKey();
//	            String password = SaeUserInfo.getSecretKey();
//	            dataSource.setUrl(value);
//	            dataSource.setUsername(user);
//	            dataSource.setPassword(password);
//			   
//		   }
//	}
//
//	@Override
//	public Object getObjectInstance(Object obj, Name name, Context nameCtx,
//			Hashtable<?, ?> environment) throws Exception {
//		
//		return null;
//	}
//
// }
